﻿using System.Windows;
using System.Windows.Input;
using Microsoft.ApplicationServer.Caching.AdminApi;

namespace MDCAdminTool.Commands
{
    public class StatisticsCacheHost : AsyncCommandBindingBase
    {
        public StatisticsCacheHost() : base()
        {
            Command = Application.Current.Resources["StatisticsCacheHost"] as ICommand;
        }

        protected override void OnExecuted( object sender , ExecutedRoutedEventArgs e )
        {
            var cache = e.Parameter as CacheHost;
            if ( cache != null )
            {
                cache.LoadStatistics();
            }
        }
        protected override void OnCanExecute( object sender , CanExecuteRoutedEventArgs e )
        {
            var service = e.Parameter as ICacheCommand;

            if (service != null)
                e.CanExecute = service.Status != ServiceStatus.Up && service.Status != ServiceStatus.Starting;
        }
    }
}